#pragma once

#include <functional>
#include <memory>
#include <random>

#include <iphlpapi.h>
#include <WS2tcpip.h>

#define WIN32_LEAN_AND_MEAN
#include <winsdkver.h>
#include <windows.h>

#include "../asio/include/asio.hpp"

using asio::ip::tcp;

class clientSession
	:public std::enable_shared_from_this<clientSession>
{
	HWND m_MainHwnd;
	asio::steady_timer dTimer;
public:
	clientSession(asio::io_service& ioservice, HWND MainHwnd);

	void timeHander(asio::error_code ec);
	tcp::socket& socket();	
	void sendmsg(const char *buf);
	void sendmsg(INT32 code);
	void start();
	void login();
	bool isLan();
	void closesock();
private:
	char code[5];
	void login_read(const asio::error_code& error);
	void handle_write(const asio::error_code& error,std::size_t);
	std::size_t cmdbufsize;
	void DoCmd();
	void handle_read(const asio::error_code& error, std::size_t bytes_transferred);
private:	
	tcp::socket m_socket;
	char data_[1024];
};